package cn.islys.controller;

import cn.islys.bean.Cls2;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

//@RestController
//@ResponseBody和@Controller的合并
@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "hello!!";
    }

    @RequestMapping("/hello2")
    public String hello2(Model model){
        model.addAttribute("demo","test");
        model.addAttribute("url","idea.webp");
        model.addAttribute("style","width:100px");
        return "thymeleaf";
    }
    @RequestMapping("/list")
    public String list(Model model){
        List<Cls2> list = Arrays.asList(new Cls2(1,"sb书中天"), new Cls2(2,"水中天"),new Cls2(3,"f5水中天"));
        model.addAttribute("list",list);
        return "list";
    }

    @RequestMapping(value = "/list1")
    @ResponseBody
    public List<Cls2> list1(Model model){
        List<Cls2> list1=Arrays.asList(new Cls2(1,"去水印1"),new Cls2(2,"去水印2"),new Cls2(3,"去水印3"));
        model.addAttribute("list1",list1);
        return list1;
    }

    @RequestMapping("/demo")
    public String demo(){
        return "httpDemo";
    }

//    @RequestMapping("/")
//    public String index(){
//        return "index";
//    }
}
